home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / editor / snmp_0_1.zip / snmp-0.1 / aka / gui / SnmpTableGui.java < prev    next >
Text File  |  1997-06-09  |  4KB  |  156 lines

  1. /*
  2. Snmp Library
  3. Copyright (C) 1997 Alex Kowalenko Associates Pty Ltd. All rights reserved.
  4.  
  5. This software maybe be free distributed, any any form, without fee, 
  6. but may not be modified in any way without express permission of 
  7. the directors of Alex Kowalenko Associates Pty Ltd. 
  8.  
  9. Alex Kowalenko Associates Pty Ltd makes no representations or
  10. warranties about the suitabililty of the software, not even the
  11. implied warranty of merchantability or fitness for any particular
  12. purpose.    
  13. */
  14.  
  15. /**
  16.  * Class Description
  17.  * @see 
  18.  * @version     $Id: SnmpTableGui.java,v 1.3 1997/05/30 11:50:39 alex Exp $
  19.  * @author      Alex Kowalenko
  20.  */
  21.  
  22. package aka.gui;
  23.  
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import java.util.*;
  27.  
  28. class SnmpTableGui implements Observer {
  29.  
  30.     private SnmpTable _app;
  31.     private Frame _f;
  32.     private List _l;
  33.    
  34.     private TextField _hostField;
  35.  
  36.     private TextField _dialogTextField;
  37.     private Dialog _dialog;
  38.  
  39.   public SnmpTableGui(SnmpTable app) {
  40.       _app = app; 
  41.       app.addObserver(this);
  42.  
  43.       _f = new Frame("Snmp Table");
  44.       initMenus();
  45.       initFrame();
  46.       _f.show();
  47.  
  48.   }
  49.     
  50.   private void initMenus() {
  51.       MenuBar bar = new MenuBar();
  52.       
  53.       // File menu     
  54.       Menu menu = new Menu("File");
  55.       MenuItem item = new MenuItem("Quit");
  56.       item.addActionListener(
  57.       new SnmpTableListener(SnmpTableListener.MENU_FILE_QUIT, _app, this));
  58.       menu.add(item);
  59.       bar.add(menu);
  60.  
  61.       // Edit Menu
  62.       menu = new Menu("Edit");
  63.       item = new MenuItem("Add variable");
  64.       item.addActionListener(
  65.       new SnmpTableListener(SnmpTableListener.MENU_EDIT_ADDVAR, _app, this));
  66.       menu.add(item);
  67.        
  68.       item = new MenuItem("Delete variable");
  69.       item.addActionListener(
  70.       new SnmpTableListener(SnmpTableListener.MENU_EDIT_DELVAR, _app, this)); 
  71.       menu.add(item);
  72.       
  73.       item = new MenuItem("Set polling interval");
  74.       item.addActionListener(
  75.       new SnmpTableListener(SnmpTableListener.MENU_EDIT_SETPOLL, _app, this));
  76.       menu.add(item);
  77.       
  78.       item = new MenuItem("Set community name");
  79.       item.addActionListener(
  80.       new SnmpTableListener(SnmpTableListener.MENU_EDIT_SETCN, _app, this));
  81.       menu.add(item);
  82.       bar.add(menu);
  83.       
  84.       _f.setMenuBar(bar);
  85.   };
  86.     
  87.   private void initFrame() {
  88.       // Layout manager is GridBag
  89.  
  90.       _f.setLayout(new BorderLayout());
  91.       _f.add(new Label("Snmp Polling"), "North");
  92.       
  93.       Panel pp = new Panel();
  94.       _f.add(pp, "Center");
  95.  
  96.       pp.add(new Label("Host"), "East");
  97.       _hostField = new TextField("localhost", 40);
  98.       _hostField.addActionListener(new SnmpTableListener(SnmpTableListener.GET_HOSTNAME,
  99.                         _app, 
  100.                         this));
  101.       pp.add(_hostField, "West");
  102.       _app.setHost("localhost");
  103.  
  104.       _l = new List(10);
  105.       _f.add(_l, "South");
  106.  
  107.       _f.pack();
  108.       _f.setSize(_f.getPreferredSize());
  109.  
  110.       _f.addWindowListener(new SnmpTableListener(_app, this));
  111.   };
  112.  
  113.   public void update(Observable o, Object arg) {
  114.       // Update List
  115.  
  116.       _l.removeAll();
  117.       Enumeration e = _app.getObjects();
  118.       while(e.hasMoreElements()) {
  119.       String[] object = (String[]) e.nextElement();
  120.       _l.add( object[0] + " = " + object[1]);
  121.       };
  122.   };
  123.  
  124.   public void doDialog(String name, String text, int action) {
  125.       _dialog = new Dialog(_f, name);
  126.       _dialog.add(new Label(text), "West");
  127.       _dialogTextField = new TextField(30);
  128.       _dialog.add(_dialogTextField, "East");
  129.       Button b = new Button("OK");
  130.       b.addActionListener(new SnmpTableListener(action, _app, this));
  131.       _dialog.add(b, "South");
  132.       _dialog.pack();
  133.       _dialog.show();
  134.       _dialog.addWindowListener(new SnmpTableListener(0, _app, _dialog));
  135.       return;
  136.   };
  137.  
  138.   public String getDialogString() {
  139.       _dialog.dispose();
  140.       if(_dialogTextField != null) {
  141.       return _dialogTextField.getText();
  142.       } else {
  143.       return new String();
  144.       };
  145.   };
  146.  
  147.   public String getHostName() {
  148.       return _hostField.getText();
  149.   };
  150.     
  151.  
  152.   public String getSelected() {
  153.       return _l.getSelectedItem();
  154.   };
  155. };
  156.